package com.tanhua.server.controller;

import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    /**
     * 今日佳人
     * GET     /tanhua/todayBest
     * 返回数据：
     * vo   TodayBest
     */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }

    /**
     * 首页推荐朋友
     * GET  /tanhua/recommendation
     * 请求参数：  page  pagesize
     * 返回值  PageResult ---List<TodayBeat>
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10") Integer pagesize) {
        //1.定义service查询
        PageResult vo = tanhuaService.recommendation(page,pagesize);
        //2.返回
        return ResponseEntity.ok(vo);
    }

    /**
     * 佳人信息
     * GET/{id}/personalInfo
     * l路径参数 userId
     * 返回值 ： TodayBest
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId) {
        TodayBest vo = tanhuaService.personalInfo(userId);
        return ResponseEntity.ok(vo);
    }

    /**
     * 查询陌生人问题
     * GET/strangerQuestions
     * Query   userId
     * 返回值：陌生人问题 String
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId) {
        String questions = tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(questions);
    }

    /**
     * 回复陌生人问题
     * POST        /strangerQuestions
     * 请求参数：
     * userId：对方的id，接收消息的一方
     * reply： 回复内容
     * 返回值无
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(@RequestBody() Map map) {
        //1.获取请求参数
        String s = map.get("userId").toString();
        Long userId = Long.valueOf(s);
        String reply = map.get("reply").toString();
        tanhuaService.reply(userId,reply);
        return ResponseEntity.ok(null);
    }

    /**
     * 查询附近人
     * GET      /search
     * 请求参数：  Query：gender性别    distance距离
     * 返回数据：NearUserVo
     */
    @GetMapping("/search")
    public ResponseEntity search(String gender, String distance) {
        List<NearUserVo> vos = tanhuaService.distance(gender, distance);
        return ResponseEntity.ok(vos);
    }

}
